﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Catalog.Interfaces;

namespace Catalog
{
    public class Renter : Client, IRenter
    {
        public Renter(string name, string address = null, string mobileNumber = null, string pictureSource =null)
            : base(name, address, mobileNumber, pictureSource)
        {
            this.RentedItems = new List<IRentable>();
            this.RentHistory = new Record();
        }

        public IList<IRentable> RentedItems { get; private set; }

        public Record RentHistory { get; private set; }

        public void Rent(IRentable item)
        {
            this.RentedItems.Add(item);
            this.RentHistory.AddRecord(item);
        }

        public override string ToString()
        {
            StringBuilder result = new StringBuilder();

            result.Append(base.ToString());

            if (this.RentedItems.Count > 0)
            {
                result.AppendFormat("\nTotal rented items: {0}\n", this.RentedItems.Count);

                foreach (var item in this.RentedItems)
                {
                    result.AppendLine(string.Format("    {0}", item.ToString()));
                }
            }

            return result.ToString();
        }
    }
}